<?php  include  $this->admin_tpl('header'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/haidaoblue/easyui.css">
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/icon.css">
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/hd_default_config.js"></script>
<script type="text/javascript" src="/template/default/statics/js/area.js"></script>
<script>var ajaxurl = "/index.php?m=admin&c=union&a=getArea";</script>
<div class="content">
  <div class="site"> <?php echo C('site_name')?> <a href="#">代理商管理</a> > 代理商列表 </div>
  <span class="line_white"></span>
  <div class="goods mt10">
    <div class="search_ind">
      <input type="hidden" name="m" value="<?php echo GROUP_NAME ?>">
      <input type="hidden" name="c" value="<?php echo MODULE_NAME ?>">
      <input type="hidden" name="a" value="<?php echo ACTION_NAME ?>">
      <span style="margin-right: 10px;">按区域</span>
      <select name='province_data' id='province'  data-options="editable:false"  onChange="loadArea(this.value, 'city');"  style="height: 26px; width:100px; float:left">
        <option value="-1" selected>--请选择省份--</option>
        <?php
                        foreach($region as $v){
						?>
        <option value="<?php echo $v["area_id"]?>" <?php if($info["province"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
        <?php
							  }
						?>
      </select>
      <select name='city_data' id='city' data-options="editable:false"  onChange="loadArea(this.value, 'district')"  style="height: 26px; width:100px; float:left">
        <option value="-1">--请选择城市--</option>
        <?php
                       
                        foreach($city as $v){
						?>
        <option value="<?php echo $v["area_id"]?>" <?php if($info["city"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
        <?php
							  }
						?>
      </select>
      <select name='district_data' id='district' data-options="editable:false" style="height: 26px; width:100px; float:left">
        <option value="-1">--请选择地区--</option>
        <?php
						
                        foreach($district as $v){
						?>
        <option value="<?php echo $v["area_id"]?>" <?php if($info["district"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
        <?php
							  }
						?>
      </select>
      <span style="margin-right: 10px;">代理商搜索 </span>
      <input id="keyword" class="easyui-textbox" name="keyword" style="width:210px;height: 26px;" prompt="输入代理商帐号/手机均可查询">
      <a id="search" href="#" class="easyui-linkbutton" style="height: 26px;padding-right: 10px;">查询</a> </div>
    <div class="login mt10" style="border: none;border-right: 1px solid #e6e6e6;">
      <table id="order_list_grid" style="width:100%;">
      </table>
    </div>
    <div class="clear"></div>
    <?php include $this->admin_tpl('copyright') ?>
  </div>
</div>
<script type="text/javascript">
		$(function() {
		//批量操作
			$(".batch").hover(function() {
				$(this).find("p").show();
				}, function() {
				$(this).find("p").hide();
			});
		})
		//改变状态架
		function corderstatus(ftype,val) {
			var arr = [];
			$("input[name='selid[]']:checked").each(function() {
				arr.push($(this).val());
			});
			if (arr.length == 0) {
				alert('请选择操作项目');
				return false;
			}
			$.post("<?php echo U('AdminOrder/ajax_status');?>", {"ftype":ftype ,"id": arr.toString(), "val": val}, function(data) {
				if (data.status == 1) {
				location.reload();
				}
			})
		}
		//切换
		$(function() {
			var tabTitle = ".mt10 dt p a";
			$(tabTitle).click(function(){
				$(this).siblings("a").removeClass("hover").end().addClass("hover");
			});
		});
	</script> 
<!--表格js--> 
<script type="text/javascript">
	var dom = $('#order_list_grid');
	var pageSize = <?php echo PAGE_SIZE?>;
	var dataurl = '<?php echo U('index')?>';
	var addurl = '<?php echo U('add')?>';
	var editurl = '<?php echo U('add',array('opt'=>'edit'))?>';
	var delurl = '<?php echo U('add',array('opt'=>'del'))?>';
	var repasswordurl = '<?php echo U('repassword')?>';
	var keyword = '<?php echo $keyword?>';
	$(function(){
		dom.datagrid({
			url:dataurl, 
			striped:true,
			width:'100%',
			checkOnSelect:false,
			fitColumns:true,
			toolbar:[{
					id:'delrows',
					text:'删除',
					iconCls:'icon-del',
				},'-',
				{
					id:'addrow',
					text:'添加',
					iconCls:'icon-add',
				},'-',
				{
					id:'exportrows',
					text:'导出',
					iconCls:'icon-export',
				},'-'
			],
			frozenColumns:[[
				{field:'id',checkbox:true}
			]],
			queryParams:{
				keyword:keyword,
			},
			scrollbarSize:0,
			pagination:true,
			pageSize:pageSize,
			pageList: [pageSize,pageSize*4,pageSize*8,pageSize*16,pageSize*32,pageSize*64],
			//可以设置每页记录条数的列表 
			columns:[[
				{field:'realname',title:'负责人姓名',width:'10%',align:'center'},
				{field:'parent_name',title:'上级代理',width:'10%',align:'center'},
				{field:'phone',title:'联系电话',width:'10%',align:'center'},
				{field:'tel',title:'微信',width:'10%',align:'center'},
				{field:'qq',title:'qq',width:'8%',align:'center'},
				{field:'address',title:'地址',width:'20%',align:'center'},
				{field:'quyu',title:'负责区域',width:'10%',align:'center'},
				{field:'add_time',title:'更新时间',width:'10%',align:'center',
					formatter:function(value,row,index){
  						return $.fn.datebox.defaults.timeformat(value);
					}
				},
				{field:'none',title:'编辑',width:'10%',halign:'center',align:'center',
					formatter:function(value,row,index){
						var edithtml = '<a href="'+editurl+'&id='+row.id+'">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;'+'<a  href="'+repasswordurl+'&id='+row.id+'">重置密码</a>&nbsp;&nbsp;&nbsp;&nbsp;';
						var delhtml = '<a onclick="dom.datagrid(\'clearSelections\').datagrid(\'clearChecked\').datagrid(\'checkRow\','+index+');$(\'#delrows\').trigger(\'click\')" href="#">删除</a>';
						return edithtml + delhtml;
					}
				},
				
			]],onLoadSuccess:function(data){
				
			}
			
		});
		$('#addrow').bind('click', function(){
			window.location.href=addurl;
		})
		//回车查询
		$('#keyword').textbox('textbox').bind('keydown',function (e) {
			if (e.keyCode == 13) {
				$('#search').trigger('click');
			}
		});
		$('#exportrows').bind('click', function(){
			var queryParams = dom.datagrid('options').queryParams;
			queryParams.province = $("#province").val();
			queryParams.city = $("#city").val();
			queryParams.district = $("#district").val();
			queryParams.keyword = $("#keyword").val();
			window.location.href="/index.php?m=admin&c=agency&a=index&act=excel&province="+queryParams.province+"&city="+queryParams.city+"&district="+queryParams.district+"&keyword="+queryParams.keyword;
		});
		$('#delrows').bind('click', function(){
			var ids = [];
			var rows = dom.datagrid('getSelections');
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].id);
			}
			if (ids.length > 0){
				$.messager.confirm('确认','您确认想要删除记录吗？',function(r){
					if (r){
						$.getJSON(delurl,
						{"id[]":ids},
						function(data){
							if(1 == data.status){// 删除成功，则需要在树中删除节点
								dom.datagrid("reload");  //重新加载
							}else{
								$.messager.alert('警告',data.info);
							}
						})
					}else{
						dom.datagrid('clearSelections').datagrid('clearChecked');
					}
				});
			}else{
				$.messager.alert('警告','请选择要删除的记录');
				return false;
			}
		});
	});
	//增加查询参数，重新加载表格
	$('#search').bind('click',function (){
		var queryParams = dom.datagrid('options').queryParams;
		//查询参数直接添加在queryParams中
		queryParams.province = $("#province").val();
		queryParams.city = $("#city").val();
		queryParams.district = $("#district").val();
		queryParams.keyword = $("#keyword").val();
		dom.datagrid('options').queryParams = queryParams;
		dom.datagrid('reload');
	})
	
</script>